package cn.cjxy.javaweb.servlet.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/**
 *  session的持久化也叫钝化与活化
 * ● 钝化：从内存到磁盘
 * ● 活化：从磁盘到内存
 * @author huangjie
 * @date 2025/9/29
 */
@WebServlet("/create")
public class CreateSession extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Person person = new Person("3", "司马相如");

        //存入session
        HttpSession session = req.getSession();
        session.setAttribute("person", person);
        //输出到网页
        PrintWriter writer = resp.getWriter();
        writer.println("访问成功....会话id"+session.getId());
        writer.println("perosn:-----"+person);
    }
}
